package com.example.rdemo.service;

import java.util.Date;
import java.util.List;

import com.example.rdemo.entity.Banner;
import com.example.rdemo.mapper.BannerMapper;
import com.example.rdemo.utils.PageResult;
import com.example.rdemo.utils.PageUtils;
import com.example.rdemo.utils.ResponseResult;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.unit.DataUnit;

/**
 * bannerService业务层处理
 * 
 * @author ruoyi
 * @date 2025-03-27
 */
@Service
public class BannerServiceImpl implements BannerService {
    @Autowired
    private BannerMapper bannerMapper;

    //查询banner
    @Override
    public Banner selectBannerById(Long id)
    {
        return bannerMapper.selectBannerById(id);
    }

    //查询banner列表
    @Override
    public PageResult selectBannerList(Banner banner,int pageNum,int pageSize)
    {
        //调用pageHelper插件
        PageHelper.startPage(pageNum,pageSize);
        List<Banner> list = bannerMapper.selectBannerList(banner);  //分页数据
        System.out.println(list.size());
        PageInfo<Banner> pageInfo = new PageInfo<>(list);
        PageResult pageResult = PageUtils.getPageResult(pageInfo);
        return pageResult;
    }

    //新增banner
    @Override
    public int insertBanner(Banner banner)
    {
//        banner.setCreateTime(DateUtils.getNowDate());
        banner.setCreateTime(new Date());
        return bannerMapper.insertBanner(banner);
    }

    //修改banner
    @Override
    public int updateBanner(Banner banner)
    {
        return bannerMapper.updateBanner(banner);
    }

    //批量删除banner
    @Override
    public int deleteBannerByIds(Long[] ids)
    {
        return bannerMapper.deleteBannerByIds(ids);
    }

    //删除banner信息
    @Override
    public int deleteBannerById(Long id)
    {
        return bannerMapper.deleteBannerById(id);
    }
}
